import send_msg from '@feidao-factory/send-msg';

export interface IUserInfo {
	_id: string;
	usercode: string;
	user_name: string;
	name_spell: string;
	is_disabled: boolean;
	create_time: number;
	productid: string;
	avatar_path: string;
	avatar_name: string;
	avatar_type: string;
	email: string;
	phone: string;
	last_login_time: number;
	phone_verified: boolean;
	email_verified: boolean;
	is_admin: boolean;
}
const GET_USER_INFO = 'loginservice.getuserinfobysessionid';

/**
 * 查看当前用户信息
 * @param action_id [string] 系统参数
 * @param sessionid [string] 系统参数
 * @param productid [string] 产品id
 */
export default async function whoami(action_id: string, sessionid: string, productid: string) {
	if (!sessionid) {
		throw new Error('Could not get sessionid');
	}
	return send_msg<IUserInfo>(action_id, sessionid, GET_USER_INFO, {
		productid,
		sessionid
	});
}
